package com.tuo51.childcare.repository;

import com.tuo51.childcare.domain.dailytask.DailyTask;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface DailyTaskRepository extends JpaRepository<DailyTask,String>, JpaSpecificationExecutor<DailyTask> {

    @Modifying
    void  deleteAllByUidAndChildrenIdAndScheduleGreaterThanAndFinishedIsFalse(String uid, String childrenId, Date date );

    @Query(value = "select * from user_daily_task t where t.uid = ?1 and t.childrenId = ?2 and " +
            "DATE_FORMAT(t.`schedule`, '%y-%m-%d') = DATE_FORMAT(?3, '%y-%m-%d')", nativeQuery = true)
    List<DailyTask> findUserDailyTasks(String uid, String childrenId, Date date);
}
